﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Ors.RInterface.Engine;
using Ors.RInterface.Engine.PInvoke;
using Ors.RInterface.Tests;

namespace Ors.RNet.xConsole
{
    
    class Program
    {
        static REngine engine;
        static void Main(string[] args)
        {
            Console.WriteLine("Interfacing R with .NET");
            Console.WriteLine("Using R engine in interactive mode demo");
            Console.WriteLine("2009 Felice Pollano for ORS S.R.L");
            Console.WriteLine("Starting engine...");
            try
            {
                engine = REngine.Create(true);
                engine.WriteMessage += new EventHandler<MessageEventArgs>(engine_WriteMessage);
                engine.AskForInput += new EventHandler<AskUserEventArgs>(engine_AskForInput);
                
                engine.Start();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }

        static void engine_AskForInput(object sender, AskUserEventArgs e)
        {
                
            Console.Write(e.Prompt);
            e.UserReply = Console.ReadLine();
        }

        static void engine_WriteMessage(object sender, MessageEventArgs e)
        {
            Console.Write(e.Message);
        }
    }
}
